package br.com.gsh.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.gsh.pojo.Usuario;
import br.com.gsh.service.UsuarioService;

public class CadastroServlet extends HttpServlet{

	private static final long serialVersionUID = -154340731751042775L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String nome = request.getParameter("nome");
		String email = request.getParameter("email");
		String senha = request.getParameter("senha");
		String nick = request.getParameter("nick");
		
		Usuario usuario = new Usuario();
		UsuarioService service = new UsuarioService();
		
		usuario.setNome(nome);
		usuario.setEmail(email);
		usuario.setSenha(senha);
		usuario.setNick(nick);
		
		try {
			service.adiciona(usuario);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		request.getSession().setAttribute("mensagem", "Cadastro realizado com Sucesso");
		response.sendRedirect("/Twitter/jsp/login.jsp");
		
	}
	

}


